package com.woniuxy.main.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import com.woniuxy.main.pojo.Messages;

public interface MessagesMapper {
	
	/**
	 * 添加聊天记录
	 * @param messages
	 */
	@Insert("insert into messages values(default,#{uid},#{createDate},#{content},#{talker})")
	public void saveChatRecord(Messages messages);
	
	/**
	 * 获取历史记录
	 * @param messages
	 * @return
	 */
	@Select("select * from messages where uid in (#{uid},#{talker}) and talker in (#{talker},#{uid})")
	public List<Messages> getHistoryMessages(Messages messages);
	
	/**
	 * 获取当前用户有关的会话--uid/talker
	 */
	//获取聊天对象id
	@Select("select distinct talker from messages where uid = #{uid}")
	public int[] messagesAsUid(Messages messages);
	//获取用户id
	@Select("select distinct uid from messages where talker = #{uid}")
	public int[] messagesAsTalker(Messages messages);
	
	/**
	 * 获取指定用户昵称
	 * @param messages
	 * @return
	 */
	@Select("select nickName from user where uid = #{uid}")
	public String getNickName(int uid);
}